import java.io.*;
import java.net.*;

public class SENDCLIENT {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        DatagramSocket datagramSocket = null;
        try {
            datagramSocket = new DatagramSocket();
        } catch (SocketException e) {
            throw new RuntimeException(e);
        }

        //准备通信数据
        String message = null;
        DatagramPacket datagramPacket = null;
        while((message = bufferedReader.readLine()) != null) {
            if ("quit".equalsIgnoreCase(message)) break;
            try {
                datagramPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("localhost"), 8888);
            } catch (UnknownHostException e) {
                throw new RuntimeException(e);
            }
            //发送
            try {
                datagramSocket.send(datagramPacket);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }



        datagramSocket.close();


    }
}
